<template>
  <div class="add-address">
    <top-header :isLeft="true" title="新建地址"></top-header>

      <div class="content">
        <a-form-model ref="ruleForm"  :model="tempAddress"  :rules="rules">
          <a-form-model-item label="姓名" prop="user_name">
            <a-input   v-model="tempAddress.user_name"/>
          </a-form-model-item>

          <a-form-model-item label="手机号" prop="user_phone" >
            <a-input v-model="tempAddress.user_phone"/>
          </a-form-model-item>

          <a-form-model-item label="地址" prop="address_location" >
            <a-input
              
             v-model="tempAddress.address"
            >
              <a-tooltip slot="suffix" title="选择地址" @click="$router.push({name:'AddressSelect'})">
                <span style="color:#063">选择地址</span>
                <i
                  class="iconfont icon-dingwei_huaban1"
                  style="color:#063;font-weight:bold"
                ></i>
              </a-tooltip>
            </a-input>
          </a-form-model-item>

          <a-form-model-item label="门牌号" >
            <a-input  v-model="tempAddress.housenum"/>
          </a-form-model-item>

          <a-form-model-item label="标签">
            <a-radio-group default-value="1" v-model="tempAddress.label">
              <a-radio-button value="0">
                家
              </a-radio-button>
              <a-radio-button value="1">
                公司
              </a-radio-button>
              <a-radio-button value="2">
                其他
              </a-radio-button>
            </a-radio-group>
          </a-form-model-item>

        <a-form-model-item>
          <a-button type="primary" block shape="round" @click="onSubmit()">
            保 存
          </a-button>
        </a-form-model-item>
        </a-form-model>
      </div>
  </div>
</template>

<script>
import TopHeader from "../components/TopHeader.vue";
import QS from "qs";
export default {
  data() {
    return {
      tempAddress:{},
// tempAddress:{
//         user_name:'',
//         user_phone:'',
//         address:'',
//         housenum:'',
//         label:'1',},
         
      rules: {
        user_name: [
          { required: true, message: "请填写姓名", trigger: "blur" },
          { min: 2, max: 5, message: "请输入正确姓名", trigger: "blur" },
        ],
        user_phone: [
          { required: true, message: "请输入正确手机号", trigger: "blur" },
        ],
      },
    };
  },
 
  components: {
    TopHeader,
  },
  created() {
      // this.getparams()
  },
   mounted(){
   
      this.tempAddress= this.$store.getters.tempAddress;
    
  },
  methods: {
      // getparams(){
      //     this.tempAddress.address = this.$route.query.address
      // },
      onSubmit(){
          let params ={
              name:this.tempAddress.user_name,
              phone:this.tempAddress.user_phone,
              address:this.tempAddress.address,
              housenum:this.tempAddress.housenum,
              label:this.tempAddress.label,
              type:this.tempAddress.type,
              user_id:localStorage.id
          };
            this.$ajax.post("/mysql/address.php", QS.stringify(params)).then((res) => {
        console.log(res);
        this.$router.replace({name:'MyshoppingAddress'})
      });
      }
  },
 
};
</script>
<style lang="scss" scoped>
.content {
    margin-top: 70px;
  width: 100%;
  height: 70%;
  padding: $common-padding;
}
</style>
